package com.atguigu.tingshu;

import com.atguigu.tingshu.common.constant.RedisConstant;
import com.xpand.starter.canal.annotation.EnableCanalClient;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@Slf4j
@EnableCanalClient  //声明当前项目是canal的客户端
public class ServiceAlbumApplication implements CommandLineRunner {
    @Autowired
    private RedissonClient redissonClient;
    public static void main(String[] args) {
        SpringApplication.run(ServiceAlbumApplication.class, args);
    }


    @Override
    public void run(String... args) throws Exception {
        RBloomFilter<Long> bloomFilter = redissonClient.getBloomFilter(RedisConstant.ALBUM_BLOOM_FILTER);
        boolean isBloomFilterTryInit = bloomFilter.tryInit(1000000, 0.00001); //参数1：存储的数据个数，参数2：误判率
        if(isBloomFilterTryInit){
            log.info("布隆过滤器初始化成功");
        }
    }
}
